<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>表单</title>
    <link rel="stylesheet" href="__STATIC__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__STATIC__/frame/static/css/style.css">
    <link rel="icon" href="__STATIC__/frame/static/image/code.png">
</head>
<body class="body">
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">选择分类</label>
        <div class="layui-input-block">
           <select id="classid">
               {foreach $class as $value}
               {if $value['id']==$data['tables_class']}
               <option value="{$value['id']}" selected>{$value['class_name']}</option>
               {else}
               <option value="{$value['id']}">{$value['class_name']}</option>
               {/if}
               {/foreach}
           </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">分支名称</label>
        <div class="layui-input-block">
            <input type="text" name="title" lay-verify="title" value="{$data['branch_name']}" autocomplete="off" placeholder="请输入分类名称" class="layui-input">
        </div>
    </div>
</form>
<div style="text-align: center">
    <button class="layui-btn" id="tijiao">提交</button>
</div>
<script src="__STATIC__/frame/layui/layui.all.js" charset="utf-8"></script>
<script src="__STATIC__/js/jquery.3.3.1.min.js" charset="utf-8"></script>
<script>
$("#tijiao").click(function () {
    var $classid = $("#classid").val();
    var $branch_name = $("[name=title]").val();
    var $id          = "{$data['id']}";
    if(!$branch_name||$branch_name==' '){
        layer.msg('请输入你要添加的分类的名称');
        return;
    };
    $.post("{:url('update/branch')}",{branch_name:$branch_name,tables_class:$classid,id:$id},function (data) {
        console.log(data);
        if(data.code==200){
           layer.msg(data.msg);
           setTimeout(function () {
               var index = parent.layer.getFrameIndex(window.name);
               parent.layer.close(index);
           },1500);
        }else{
            layer.msg(data.msg);
        }
    })
})
</script>
</body>
</html>